package com.dollama.random.model.impl;

import com.dollama.random.model.RandomModel;
import com.dollama.random.presenter.RandomPresenter;
import com.dollama.random.utils.SortUtil;

import java.util.ArrayList;
import java.util.Random;

/**
 * Created by tony on 2017/5/10.
 */

public class SortTestImpl implements RandomModel {
    @Override
    public void createRandomNumber(RandomPresenter randomPresenter) {
        Random random = new Random();
        ArrayList<Integer> arrayList = new ArrayList<>(),arrayList1;
        for (int a = 0 ; a< 10 ; a++) {
            arrayList.add(random.nextInt(1000));
        }
        String resultStr = arrayList.toString();
        SortUtil.CompareListener listener = new SortUtil.CompareListener() {
            @Override
            public boolean compare(Object obj1, Object obj2) {
                if (obj1 == null&&obj2!=null) {
                    return false;
                } else if (obj1!=null&&obj2==null) {
                    return true;
                }
                if (((Integer) obj1).compareTo(((Integer)obj2))>0) {
                   return true;
                }

                return false;
            }
        };

        arrayList1 = SortUtil.recursionSort(arrayList,listener);
        resultStr = resultStr +"\n//" + arrayList1.toString();
        randomPresenter.showRandom(resultStr);

    }


}
